package com.zhou.cloud.service.impl;

import com.zhou.cloud.dao.entity.Product;
import com.zhou.cloud.dao.mapper.ProductMapper;
import com.zhou.cloud.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @descrition:
 * @author: zhouyongjun
 * @date: 2022/11/22
 **/
@Service
public class ProductServiceImpl implements IProductService {
    @Autowired
    ProductMapper mapper;

    @Override
    public List<Product> getAllList() {
        return mapper.selectAll();
    }

    @Override
    public List<Product> getCanSoldList() {
        return mapper.selectCanSoldList();
    }

    @Override
    public List<Product> getSoldOutList() {
        return mapper.selectSoldOutList();
    }

    @Override
    public Product get(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public boolean sold(Long id, int num) {
        int result =  mapper.updateNumById(id,num);
        return result > 0;
    }

    @Override
    public boolean soldFromCache(Long pid, Integer delNum) {
        return false;
    }
}
